<?php
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
//系统配置

$config=$this->config();
$member=m('member')->get_uidopenid();


$op=!empty($_GPC['op'])?$_GPC['op']:'index';
if ($op=='index') {
    $cid=$_GPC['id'];
    $where=" uniacid=:uniacid ";
    $array=[':uniacid'=>$_W['uniacid']];
    if($cid){
        $where=" category=:cid ";
        $array[':cid']=$cid;
    }

    $categorylist=m('category')->getList(array('parentid'=>'>0','enabled'=>1,'order'=>' displayorder asc'));

    include $this->template('index'); 

	
}elseif($op=='upload'){
    $flag=$_GPC['flag'];
    $file = $_FILES['fileName'.$flag];//得到传输的数据
    
    //得到文件名称
    $name = $file['name'];
    $type = strtolower(substr($name,strrpos($name,'.')+1)); //得到文件类型，并且都转化成小写
    $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型
    //判断文件类型是否被允许上传
    if(!in_array($type, $allow_type)){
      //如果不被允许，则直接停止程序运行
      return ;
    }
    //判断是否是通过HTTP POST上传的
    if(!is_uploaded_file($file['tmp_name'])){
      //如果不是通过HTTP POST上传的
      return ;
    }
	$upload_path = "../addons/xuan_zy/public/user/"; //上传文件的存放路径
	$url=$upload_path.md5($file['name'].time()).'.'.$type;
	//开始移动文件到相应的文件夹
    if(move_uploaded_file($file['tmp_name'],$url)){
	  
		include $this->template('upload');
    }else{
      echo "Failed!";
    }

}elseif($op=='upload2'){
    $avatar=$_GPC['avatar'];

    $acc = WeAccount::create($_W['acid']);
    $file=$acc->downloadMedia(array('type'=>'image','media_id'=>$avatar));
    echo json_encode(['file'=>$file]);
}

	
 
